package LeetCode.LeetCode2;

/**
 * 乘积小于K的子数组
 * @author lumin
 * @date 2022/04/10 19:49
 **/
public class Num713 {
    public static int numSubarrayProductLessThanK(int[] nums, int k) {
        if (k <= 1) return 0;
        int prod = 1, ans = 0, left = 0;
        for (int right = 0; right < nums.length; right++) {
            prod *= nums[right];
            while (prod >= k) prod /= nums[left++];
            ans += right - left + 1;
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] nums = {10,2,5,6};
        System.out.println(numSubarrayProductLessThanK(nums,100));
    }
}